// import parseTime, formatTime and set to filter
import store from '../store'
// 过滤时间
export { parseTime } from '@/utils'

// 字典过滤
export function filterDictionary(v, key) {
  if (v === null || v === '' || v === undefined) {
    return '-'
  }
  if (!key) {
    throw new Error(`请先配置字典名称！`)
  }
  const dictionary = store.getters.dictionaryList[key]
  if (dictionary && dictionary.length) {
    let list
    if (v.toString().indexOf(',') !== -1) {
      list = v.split(',')
    } else {
      list = [v]
    }

    const resList = []
    list.forEach(item => {
      const obj = dictionary.find(it => {
        return it.code.toString() === item.toString()
      })
      resList.push(obj ? obj.value : item)
    })
    return resList.join('，')
  } else {
    return v
  }
}
